/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package IO;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author rmsalasm
 */
import java.io.File;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.util.ArrayList;
import javazoom.jl.player.Player;


public class PlayMP3 {

    /**
     * Creates new form PlayMP3
     */
    private File file;
    private Player player;
    public PlayMP3() {
    }
    
    public void close() { 
        if (player != null) 
            player.close();
    } 

    // play the MP3 file to the sound card
    public void play(String audioPath) {
        try {
        String audioFolder = "/Carpeta Maestra/Audios/";
        String basePath = new File("").getAbsolutePath();
        String mp3File = basePath + audioFolder + audioPath;
            
            FileInputStream fis     = new FileInputStream(mp3File);//(this.file.getAbsolutePath());
            BufferedInputStream bis = new BufferedInputStream(fis);
            player = new Player(bis);
        }
        catch (Exception e) {
            System.out.println("Problem playing file " + file.getName());
            System.out.println(e);
        }
        // run in new thread to play in background
        new Thread() {
            public void run() {
                try { player.play(); }
                catch (Exception e) { System.out.println(e); }
            }
        }.start();
    }               
}
